package softstarter.launching;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;

import javax.swing.SwingWorker;


public class URIExecutor extends SwingWorker<ExecutionResult, Void> {

    private URI URIToBeOpened;
    
    public URIExecutor(URI fileToBeLaunched) {
        this.URIToBeOpened = fileToBeLaunched;
    }
    
    @Override
    protected ExecutionResult doInBackground() throws Exception {
        
        boolean successfullyLaunched = openURI();
        
        if(successfullyLaunched)
            return ExecutionResult.SUCCESSFULLY_LAUNCHED;
        else
            return ExecutionResult.FAILED_TO_LAUNCH;
     
    }
    
    private boolean openURI() {

    	Desktop desktop = Desktop.getDesktop();
        
        try {
            desktop.browse(URIToBeOpened);
        }
        catch (IOException ioe) {
            ioe.printStackTrace();
            return false;
        }
        
        return true;
    }
    
}
